/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - graphics/shaders
// Copyright( c) 2014.  All Rights Reserved
//
// File:		AEShaderConstantTableEntry.inl
// Author:		Gianluca Belardelli
// Date:		29/01/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AESHADERCONSTANTTABLEENTRY_INL_
#define _AESHADERCONSTANTTABLEENTRY_INL_

AE_FORCEINLINE AEShaderConstantTableEntry::AEShaderConstantTableEntry( void )
{
	nRegisterIndex = -1;
	eValueType = AEVALUETYPE_UNKNOWN;
	nArrayElements = 1;
	szVarname[0] = '\0';
}

AE_FORCEINLINE AEShaderConstantTableEntry &AEShaderConstantTableEntry::operator= (const AEShaderConstantTableEntry &other )
{
	strncpy( szVarname, other.szVarname, MAX_CONSTANT_NAMELEN );
	eValueType = other.eValueType;
	nArrayElements = other.nArrayElements;
	nRegisterIndex = other.nRegisterIndex;

	return *this;
}

AE_FORCEINLINE AEBOOL32 AEShaderConstantTableEntry::IsValid( void ) const 
{
	return nRegisterIndex >= 0;
}

AE_FORCEINLINE AEBOOL32 AEShaderConstantTableEntry::IsConstantBufferEntry( void ) const 
{
	if( !IsValid() || eValueType == AEVALUETYPE_UNKNOWN || eValueType == AEVALUETYPE_STRING 
		|| eValueType == AEVALUETYPE_TEXTURE || eValueType == AEVALUETYPE_CUBEMAP
		|| eValueType == AEVALUETYPE_TEXTURE3D || eValueType == AEVALUETYPE_TEXTURE2DARRAY )
		return AEFALSE;

	// variables that start with _noExport will not be added to the constant table
	//if (!_strnicmp(m_sVarname.AsChar(),"_noExport",strlen("_noExport")))
	//return false;

	return AETRUE;
}

AE_FORCEINLINE AEBOOL32 AEShaderConstantTableEntry::IsSamplerType( void ) const
{
	return( eValueType == AEVALUETYPE_TEXTURE || eValueType == AEVALUETYPE_CUBEMAP
		|| eValueType == AEVALUETYPE_TEXTURE3D || eValueType == AEVALUETYPE_TEXTURE2DARRAY );
}

AE_FORCEINLINE AEINT32 AEShaderConstantTableEntry::GetRegisterCount( void ) const 
{
	return GetRegisterCountFromValueType( eValueType ) * nArrayElements;
}

AE_FORCEINLINE void AEShaderConstantTableEntry::GetRegisterRange( AEINT32 &nFirst, AEINT32 &nLast ) const
{
	nFirst = nRegisterIndex;
	nLast = nFirst + GetRegisterCount() -1;
}

#endif // _AESHADERCONSTANTTABLEENTRY_INL_
